package com.d0325;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class TestLocal {
    public static void main(String[] args) {
       /* LocalDateTime ldt=LocalDateTime.now();
        LocalDateTime ldt2=LocalDateTime.of(2020,12,8,12,12,21);
        System.out.println(ldt);
        System.out.println(ldt2);*/
        DateTimeFormatter dtf1=DateTimeFormatter.ofPattern("yyyy/MM/dd");
        DateTimeFormatter dtf2=DateTimeFormatter.ofPattern("hh时mm分ss秒");
        DateTimeFormatter dtf3=DateTimeFormatter.ofPattern("yyyy/MM/dd hh时mm分ss秒");
        LocalDate date=LocalDate.now();
        LocalTime time=LocalTime.now();
        LocalDateTime datetime=LocalDateTime.now();

//		进行格式化
        System.out.println(date.format(dtf1));
        System.out.println(time.format(dtf2));
        System.out.println(datetime.format(dtf3));
        //使用DateTimeFormatter对象进行转换
        String str1="2001/12/03";
        String str2="12时23分34秒";
        String str3="2001/12/03 12时23分34秒";
        LocalDate date2=LocalDate.parse(str1,dtf1);
        LocalTime time2=LocalTime.parse(str2,dtf2);
        LocalDateTime datetime2=LocalDateTime.parse(str3,dtf3);
        System.out.println(date2);
        System.out.println(time2);
        System.out.println(datetime2);

    }
}
